﻿/*
 * 设计模式 - 观察者模式
 * 目的: 让下面的对象一致的行动
 */


Teacher teachers = new Teacher();
teachers.Add(new Action_1());
teachers.Add(new Action_2());

teachers.Command();


interface IAction
{
    void Do();
}

class Action_1 : IAction
{
    public void Do()
    {
        Console.WriteLine("Action_1. 做了的行为");
    }
}

class Action_2 : IAction
{
    public void Do()
    {
        Console.WriteLine("Action_2. 做了行为");
    }
}


class Teacher
{
    private List<IAction> actions = new List<IAction>();

    public void Add(IAction action)
    {
        actions.Add(action);
    }

    public void Remove(IAction action)
    {
        actions.Remove(action);
    }


    public void Command()
    {
        actions.ForEach(x => x.Do());
    }

}